/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package xmarti.vacaxm.utils;

import java.awt.Color;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author xmarti
 */
public class Utils {
    /**
     * Converteix una data en format texte en format data
     * @param date                  Cadena de texte 
     * @return  una data en format java.util.date
     
     */
    public static Date getDateSimpleFormat(String date) {
        Date testDate=null;
        try{
            if(date.contains("-")){
                testDate= new SimpleDateFormat("dd-MM-yyyy").parse(date);
            }else{
                testDate= new SimpleDateFormat("dd/MM/yyyy").parse(date);
            }    
        }catch (ParseException e){
            return null;
        }        
        return testDate;
    }
    
     public static String getStringDate(Date date){
        String sDate="";
       
        if(date != null)
            sDate= new SimpleDateFormat("dd/MM/yyyy").format(date);                                
        
        return sDate;        
    }
     public static Color getColorCow(){
         return Color.getHSBColor(244, 197, 138);
     }
     public static Color getColorBull(){
         return Color.getHSBColor(255, 104, 104);
     }
     public static Color getColorCalf(){
         return Color.getHSBColor(204, 100, 100);
     }
     public static Color getColorError(){
         return Color.RED;
     }
     public static Color getColorOk(){         
         //return Color.getHSBColor(0,102,255);
         return Color.BLUE;
     }
     
     public static int confirmSaveOptionPane(String description){
        Object[] options = {TDSLanguageUtils.getMessage("jOptionPane.JLabel.yes.caption"),TDSLanguageUtils.getMessage("jOptionPane.JLabel.no.caption")};
        return JOptionPane.showOptionDialog(null,description,TDSLanguageUtils.getMessage("jOptionPane.JLabel.save.caption"),
                JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,
                options,  //the titles of buttons
                options[0]); //default button title 
     }
     public static int confirmRemoveOptionPane(String description){
        Object[] options = {TDSLanguageUtils.getMessage("jOptionPane.JLabel.yes.caption"),TDSLanguageUtils.getMessage("jOptionPane.JLabel.no.caption")};
        return JOptionPane.showOptionDialog(null,description,TDSLanguageUtils.getMessage("jOptionPane.JLabel.remove.caption"),
                JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,
                options,  //the titles of buttons
                options[0]); //default button title 
     }
     
     
}
